package itxx.itxx;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

/*
 * 获取输入流对象
 * */

@WebServlet("/ServletDemo2")
public class ServletDemo2 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        //获取字符流(必须post方式)
//        BufferedReader br = request.getReader();
//        String line;
//        while((line=br.readLine())!=null){
//            System.out.println(line);
//        }
//        br.close();

        //字节流
        ServletInputStream sis = request.getInputStream();
        byte[] bytes = new byte[1024];
        int len;
        while ((len=sis.read(bytes)) != -1) {
            System.out.println();
        }

    }
}
